package com.ztf666.articlereview.service.impl;

import com.ztf666.articlereview.entity.Article;
import com.ztf666.articlereview.mapper.ArticleMapper;
import com.ztf666.articlereview.mapper.UserArticleMapper;
import com.ztf666.articlereview.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author z
 * @date 2022/2/21 下午12:06
 */
@Service
@Transactional(rollbackFor = RuntimeException.class)
public class ArticleServiceImpl implements ArticleService {
    private ArticleMapper articleMapper;

    @Autowired
    public void setArticleMapper(ArticleMapper articleMapper) {
        this.articleMapper = articleMapper;
    }

    private UserArticleMapper userArticleMapper;
    @Autowired
    public void setUserArticleMapper(UserArticleMapper userArticleMapper) {
        this.userArticleMapper = userArticleMapper;
    }

    @Override
    public void addArticle(Integer userId, String name, String desc) {
        int aid = articleMapper.addArticle(name, desc);
        userArticleMapper.addId(userId,aid);
    }

    @Override
    public List<Article> findArticle(int aid) {
        List<Article> articles = articleMapper.selectArticleByAid(aid);
        return articles;
    }
}
